package com.aurora_manito.xiaomi.entity;

import java.util.Arrays;
import java.util.List;

//网站建设技术pageBean
public class PageBean<T> {
    private int currentPageNO = 1;
    private int pageSize = 5;
    private int totalRecordCount;          //列表有多少内容
    private int totalPageCount;            //总页数
    private int startRowNO;                 //没用到
    protected List<T> pageList;             //数据列表
    private int startPage;          // 开始页数
    private int endPage;            // 结束页数
    private int[] pageNumbers;      //没用到

    public PageBean() {
    }

    //当前页号，每页大小 ，总记录数
    public PageBean(int currentPageNO, int pageSize, int totalRecordCount, List<T> pageList) {
        this.currentPageNO = currentPageNO;
        this.pageSize = pageSize;
        this.totalRecordCount = totalRecordCount;
        this.pageList = pageList;
        //计算总页数
        this.totalPageCount=totalRecordCount % pageSize == 0 ? totalRecordCount / pageSize : totalRecordCount / pageSize + 1;
        //计算导航的开始页和结束页
        //1 正常的情况   当前页面 -4  +5
        this.startPage=currentPageNO-4;
        this.endPage=currentPageNO+5;
        //2 当前页码小于5
        if(currentPageNO<5){
            this.startPage=1;
            this.endPage=10;
        }
        //3当前页大于 总页数-5
        if(currentPageNO>(totalPageCount-5)){
            this.startPage=totalPageCount-9;
            this.endPage=totalPageCount;
        }
        //4总页数小于10
        if(totalPageCount<10){
            this.startPage=1;
            this.endPage=totalPageCount;
        }

    }

    public int getCurrentPageNO() {
        return currentPageNO;
    }

    public void setCurrentPageNO(int currentPageNO) {
        this.currentPageNO = currentPageNO;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecordCount() {
        return totalRecordCount;
    }

    public void setTotalRecordCount(int totalRecordCount) {
        this.totalRecordCount = totalRecordCount;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getStartRowNO() {
        return (currentPageNO - 1) * pageSize;
    }

    public void setStartRowNO(int startRowNO) {
        this.startRowNO = startRowNO;
    }

    public List<T> getPageList() {
        return pageList;
    }

    public void setPageList(List<T> pageList) {
        this.pageList = pageList;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    public int[] getPageNumbers() {
        return pageNumbers;
    }

    public void setPageNumbers(int[] pageNumbers) {
        this.pageNumbers = pageNumbers;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "currentPageNO=" + currentPageNO +
                ", pageSize=" + pageSize +
                ", totalRecordCount=" + totalRecordCount +
                ", totalPageCount=" + totalPageCount +
                ", startRowNO=" + startRowNO +
                ", pageList=" + pageList +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                ", pageNumbers=" + Arrays.toString(pageNumbers) +
                '}';
    }
}
